package org.liuwei.concucrent.base03.RentrantLock01;

import java.util.concurrent.locks.ReentrantLock;
/**
 * 
* @Title: ReentrantLockRunnable.java 
* @Package org.liuwei.concucrent.base03.ReentrantLock01 
* @Description: TODO(可重入单线程可以重复进入，但要重复退出) 
* @author 刘伟  15818570028@163.com   
* @date 2016年8月20日 下午7:36:30 
* @version V1.0
 */
public class ReentrantLockRunnable01 implements Runnable {
	public static ReentrantLock lock = new ReentrantLock();
	public static int count = 0;

	public void run() {

		for (int i = 0; i < 10000; i++) {
			lock.lock();
			lock.lock();
			try {
				count++;
			}finally {
				lock.unlock();
				lock.unlock();
			}
		}
	}

	public static void main(String[] args) throws InterruptedException {
		ReentrantLockRunnable01 r = new ReentrantLockRunnable01();
		Thread t = new Thread(r);
		Thread t2 = new Thread(r);
		t.start();
		t2.start();
		t.join();
		t2.join();
		System.out.println(count);
	}

}
